//
//  YHNavigationController.swift
//  YHSwiftProject
//
//  Created by LYH on 2018/11/2.
//  Copyright © 2018年 LYH. All rights reserved.
//

import UIKit

class YHNavigationController: UINavigationController,UINavigationControllerDelegate {

    var popDelegate: UIGestureRecognizerDelegate?
    
    override func viewDidLoad() {
        super.viewDidLoad()
//    self.navigationBar.barTintColor = themeColor
    
    //导航栏背景图片
    self.navigationBar.setBackgroundImage(UIImage.init(named: "navi_State"), for: .default)

    //title 颜色  大小
    self.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white , NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 17)]

    //解决侧滑失效
    self.popDelegate = self.interactivePopGestureRecognizer?.delegate
    self.delegate = self
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.viewControllers.count>0 {
           viewController.hidesBottomBarWhenPushed = true //跳转后隐藏tabbar
        }
        super.pushViewController(viewController, animated: true)
        
        
    }
    
 //UINavigationControllerDelegate方法
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        //实现滑动返回功能
         //清空滑动返回手势的代理就能实现
        if viewController == self.viewControllers[0] {
          self.interactivePopGestureRecognizer!.delegate = self.popDelegate
        }else
        {
            self.interactivePopGestureRecognizer!.delegate = nil
        }
        
    }
    //改变状态栏颜色
    //info.plist中的View controller-based status bar appearance yes
    /// 重写此方法让 preferredStatusBarStyle 在viewController 响应
    override var childForStatusBarStyle: UIViewController? {
        return self.topViewController
    }
 
}
